﻿using System;
using System.Data;
using System.Web.UI.WebControls;
using BLL;
using Utils;
namespace UI.ModEmployee
{
    public partial class EmpInsuranceList : System.Web.UI.Page
    {
        EmpInsuranceBiz empInsuranceBiz = new EmpInsuranceBiz();

      

        string account = "";
        protected void Page_Load(object sender, EventArgs e)
        {
          
            btnAdd.Attributes.Add("onclick", "javascript:ShowLink('EmpInsuranceAdd.aspx',800,550);");
            btnIn.Attributes.Add("onclick", "javascript:ShowLink('EmpInsuranceImport.aspx',600,480);");

            if (Session["user"] != null)
            {
                User user = Session["user"] as User;
                account = user.Account;
            }
            else
            {
                JSUtility.Alert(this, "您没有登录!请先登录。");
                return;
            }

            if (!IsPostBack)
            {
                DateTime dTime = System.DateTime.Now;

                //display to End info
                BondGvList("", dTime.AddDays(-30).ToString("yyyy-MM-dd"), dTime.AddDays(30).ToString("yyyy-MM-dd"), "", "EndTime");


                //more than 10 days 
                // int thisDay = dTime.Day;
                //if (thisDay == 15 || thisDay == 20 || thisDay == 25)
                //  empInsuranceBiz.UpdateToEnd();


            }
        }

        protected void btnEmSearch_Click(object sender, EventArgs e)
        {
            if (!AccountBiz.CheckRight(account, "EmpInsuranceList.aspx", RightChar.Ser))
            {
                JSUtility.Alert(this, "您没有查询权限！");
                return;
            }
            string serWord = txtSerWord.Text.Trim();
            string bTime = txtBtime.Text.Trim();
            string eTime = txtEtime.Text.Trim();
            string statu = ddlStatu.SelectedValue;
            string timeType = ddlTimeType.SelectedValue;
            //if (serWord == "" && bTime == "" && eTime == "")
            //{
            //    bTime = System.DateTime.Now.AddMonths(-2).ToString("yyyy-MM-dd");
            //    eTime = System.DateTime.Now.ToString("yyyy-MM-dd");
            //}
            //if (StringUtility.GetDiffDays(bTime, eTime) > XmlUtility.GetNumFormConfig("daysOfSearch"))
            //{
            //    JSUtility.Alert(this, "查询日期间隔不能大于" + XmlUtility.GetNumFormConfig("daysOfSearch") + "天！");
            //    return;
            //}
            BondGvList(serWord, bTime, eTime, statu, timeType);
        }
        protected void BondGvList(string serWord, string bTime, string eTime, string statu, string timeType)
        {
            DataTable dt = empInsuranceBiz.GetLists(serWord, bTime, eTime, statu, timeType);
            if (dt.Rows.Count > 0)
                lbAmount.Text = "合计:    " + dt.Rows.Count;
            else
                lbAmount.Text = "无数据";
            gvList.DataSource = dt;
            gvList.DataBind();
        }

        protected void btnExcel_Click(object sender, EventArgs e)
        {
            if (!AccountBiz.CheckRight(account, "EmpInsuranceList.aspx", RightChar.Out))
            {
                JSUtility.Alert(this, "您没有导出权限！");
                return;
            }
            string serWord = txtSerWord.Text.Trim();
            string bTime = txtBtime.Text.Trim();
            string eTime = txtEtime.Text.Trim();
            string statu = ddlStatu.SelectedValue;
            string timeType = ddlTimeType.SelectedValue;
            DataTable dt = empInsuranceBiz.GetLists(serWord, bTime, eTime, statu, timeType);
            if (dt != null)
                ExcelUtility.ExportDsToXls(this, dt, "DutyInsurance.xls");
            // ExcelUtility.GridViewToExcel(gvList, "DutyInsurance.xls");
        }

        protected void gvList_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Header)
            {
                e.Row.Cells[0].Visible = false;
            }
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#F3F8F8'");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
            }
        }


    }
}